import wepy from 'wepy'
export default class extends wepy.mixin {
	data = {
		// 商品id
		id: '',
		// 用户id
		userId: '',
		// skuid
		skuAttrValueIds: '',
		// 商品详情数据
		goodsdatilist: {},
		// 商品信息
		goods_info: {
			// 商品原价
			goods_opr: '100.00',
			goods_img: '',
		},
		// 商品选择
		goodsMues: {
			// 规格
			goodsTitle: '',
			// 颜色
			goodsColor: '',
			// 购买商品数量
			goodsNum: 1,
		},
		//临时商品数量
		lsnum: 1,
		// 规格页面弹出层控制
		show: false,
		sho: false,
		// 规格栏信息
		guigeInfo: '请选择商品规格',
		// 控制颜色规格样式
		isColorActive: 0,
		// 控制尺码规格样式
		isTitleActive: 0,
		// 收藏样式
		isChecked: false,
		// 默认地址
		getaddressDeftInfo: {},
		// 点击购买时的订单id
		orderId: '',
		// 商品关联id
		seckillGoodId: '',
		activeName: '',
		// 满减活动数据
		ManJian: [],
		sku: '',
		title: '',
		skuPrice: '',
		imgPath: '',
		showing: false,
		quxiao: false,
		// 活动满减价格
		manJianMOney: '',
		fangda: false,
		satisfyPrice: '',
		imgMaskShow: true,
		hidden: true,
		// 图片保存开关
		imgSaveBell: false,
		// 配送信息
		sendLi: '',
		shouing: false,
		tempFilePath: '',
		fenxiang: false,
		showeding: false,
		youhuiInfo: {},
		urls: wepy.$instance.globalData.baseURl,
		zhanweit: '2020-05-22/202005221838201590143900270_p0w5g.png',
		statesp: 0,
		savedImgUrl: '',
		// 海报start
		showSharePic: false, // 分享海报显示隐藏
		time: 0,
		timeData: {},
		daojishi: false,
		duihuan: false,
		//积分兑换方式
		jfdhfs: '',
		// 购物车id
		shoppingCartId: '',
		//海报商品名称
		shareTitle: '',
		// 海报商品图
		shareCoverImg: '',
		//海报小程序码
		shareQrImg: '', 
		//海报logo
		rjlogo: wepy.$instance.globalData.baseURl + '2020-06-28/202006281200331593316833808_w2u1j.png',
		// 生成海报图片
		sharePicUrl: ''
	}
	onLoad(options) {
		this.activeName = options.activeName
		this.id = options.id
		if (options.skuAttrValueIds) {
			this.skuAttrValueIds = options.skuAttrValueIds
		}
		if (options.seckillGoodId) {
			this.seckillGoodId = options.seckillGoodId
			this.$parent.globalData.seckillGoodId = options.seckillGoodId
		}
		if (options.shoppingCartId) {
			this.shoppingCartId = options.shoppingCartId;
		}
		// 商品详情数据
		this.getGoodsDatil()
		//满减活动
		this.getManJian(options.id)
		let cid = wepy.getStorageSync('userId')
		this.userId = cid
		this.getAddressdefalt()
		// 显示分享
		wepy.showShareMenu({
			withShareTicket: true,
		})
		this.getsendInfo()
	}
	onShareAppMessage() {
		var that = this
	}
	onShow() {
		this.$parent.globalData.seckillGoodId = this.seckillGoodId;
	}
	computed = {
		isEmpty() {
			if (this.ManJian.length <= 0) {
				return false
			}
			return true
		},
	}
	methods = {
		ChangeDao(e) {
			this.timeData = e.detail
		},
		jfdh() {
			if (this.goodsdatilist.isPub == 1) {
				return wepy.noToast('此商品已下架')
			} else {
				this.duihuan = true;
			}
		},
		jfClose() {
			this.duihuan = false;
		},
		jfqd() {
			var that = this;
			var kyjifen = that.goodsdatilist.kyjifen;
			var allPoint = that.goodsdatilist.allPoint;
			var point = this.goodsdatilist.point;
			if (that.jfdhfs == 3) {
				if (that.lsnum * allPoint > kyjifen) {
					return wepy.noToast('当前可用积分不足')
				} else {
					that.ggvvc()
				}
			}
			if (that.jfdhfs == 4) {
				if (that.lsnum * point > kyjifen) {
					return wepy.noToast('当前可用积分不足')
				} else {
					that.ggvvc()
				}
			}
		},
		//全积分兑换
		qjfdh() {
			var kyjifen = this.goodsdatilist.kyjifen;
			var allPoint = this.goodsdatilist.allPoint;
			this.jfdhfs = "3";
			if (kyjifen >= allPoint) {
				if (wepy.getStorageSync('userId')) {
					this.show = true;
				} else {
					wx.navigateTo({
						url: '../../pages/Authorization/authorization',
					})
				}
			} else {
				return wepy.noToast('当前可用积分不足')
			}
		},
		//积分+现金兑换
		jfxjdh() {
			var kyjifen = this.goodsdatilist.kyjifen;
			var point = this.goodsdatilist.point;
			this.jfdhfs = "4";
			if (kyjifen >= point) {
				if (wepy.getStorageSync('userId')) {
					this.show = true;
				} else {
					wx.navigateTo({
						url: '../../pages/Authorization/authorization',
					})
				}
			} else {
				return wepy.noToast('当前可用积分不足')
			}
		},
		// 海报开始
		showPic() {
			if (wepy.getStorageSync('userId')) {
				this.geterweiMa()
				let sharePicUrl = this.sharePicUrl
				if (sharePicUrl != '') {
					this.showSharePic = true
				} else {
					wx.showToast({
						title: '图片生成中',
						mask: true,
						icon: 'loading',
						duration: 1000,
					})
					this.share = false
					let logo = '' //用户头像
					let rjlogo = ''
					let headIcon = '' //海报商品图
					let code = '' //海报二维码
					this.getLogo()
						.then((headUrl) => {
							headIcon = headUrl
							return this.getLogo()
						})
						.then((shareCoverImg) => {
							logo = shareCoverImg
							return this.getCode()
						})
						.then((codeUrl) => {
							code = codeUrl
							return this.getrjlogo()
						})
						.then((rjlogo) => {
							rjlogo = rjlogo
							this.drawImg(rjlogo, logo, headIcon, code)
						})
				}
			} else {
				wx.navigateTo({
					url: '../../pages/Authorization/authorization',
				})
			}
		},
		// 海报结束
		onClickIcon() {
			console.log('点击图标')
		},
		// 立即购买
		async onClickButton() {
			this.show = true
			this.statesp = 0
		},
		// 加入购物车
		async addBtn() {
			this.statesp = 1
			this.show = true
		},
		// 加入购物车
		async jiaruc() {
			if (wepy.getStorageSync('userId')) {
				this.gouwuche()
			} else {
				wx.navigateTo({
					url: '../../pages/Authorization/authorization',
				})
			}
		},
		// 关闭弹出层
		onClose() {
			this.show = false
		},
		onClos() {
			this.sho = false
		},
		// 打开弹出层
		onOpen() {
			this.show = true
			this.statesp = 2
		},
		showPopup() {
			this.sho = true
		},
		onDakai() {
			console.log('点击打开')
			console.log(this.showing)
			this.showing = true
		},
		onCloseing() {
			this.showing = false
		},
		// 图片放大
		preview(current) {
			console.log(current, '--------')
			wepy.previewImage({
				// 所有图片的路径
				urls: this.goodsdatilist.images.map((x) => x.imgPath),
				// 当前默认看到的图片
				current: current,
			})
		},
		fangBig(current) {
			console.log('current', current)
			var lists = []
			lists.push(current)
			wepy.previewImage({
				// 所有图片的路径
				urls: lists.map((x) => x),
				// 当前默认看到的图片
				current: current,
			})
		},
		onclo() {
			this.fangda = false
		},
		// 商品数量选择
		onChange(e) {
			console.log(e)
			this.lsnum = e.detail
		},
		//立即购买
		goumai() {
			if (wepy.getStorageSync('userId')) {
				this.guigeInfo = this.goodsMues.goodsTitle + '   ' + this.lsnum + '件'
				this.$parent.globalData.seckillGoodId = this.$parent.globalData.seckillGoodId
				this.$apply()
				const goods_info = {
					goodsid: this.id,
					skuAttrValueIds: this.skuAttrValueIds,
					num: this.lsnum.toString(),
				}
				const goodInfo = {
					title: this.title,
					imgPath: this.imgPath,
					sku: this.goodsMues.goodsTitle.substr(0, this.goodsMues.goodsTitle.length).split(','),
					point: this.goodsdatilist.point,
					skuPrice: this.goodsdatilist.skuPrice,
					allPoint: this.goodsdatilist.allPoint,
					isPoint: this.goodsdatilist.isPoint,
					payType: '0'
				}
				this.$parent.globalData.goods_info = goods_info
				this.$parent.globalData.goodInfo = goodInfo
				this.show = false
				wepy.navigateTo({
					url: '../../pages/confirmOrder/confirmorder?state=' + 1,
				})
			} else {
				wx.navigateTo({
					url: '../../pages/Authorization/authorization',
				})
			}
		},
		// 确认
		onSubmit() {
			if (this.goodsdatilist.skuNum < 1) {
				return wepy.noToast('此规格商品库存不足,请重新选择')
			} else {
				if (wepy.getStorageSync('userId')) {
					if (this.statesp == 1) {
						//加入购物车
						this.gouwuche()
					} else if (this.statesp == 0) {
						//立即购买
						this.goodsMues.goodsTitle = ''
						this.skuAttrValueIds = ''
						//规格开始
						var list = this.goodsdatilist.attr_group_list
						var skuAttrValueIds = ''
						for (var i = 0; i < list.length; i++) {
							for (var j = 0; j < list[i].attrValues.length; j++) {
								if (list[i].attrValues[j].checked == true) {
									this.goodsMues.goodsTitle +=
										list[i].attrValues[j].attrValueName + ''
									skuAttrValueIds += list[i].attrValues[j].attrValueId + ','
								}
							}
						}
						this.skuAttrValueIds = skuAttrValueIds.substr(
							0,
							skuAttrValueIds.length - 1
						)
						this.sku = ''
						for (var i = 0; i < list.length; i++) {
							for (var j = 0; j < list[i].attrValues.length; j++) {
								if (list[i].attrValues[j].checked == true) {
									this.sku += list[i].attrValues[j].attrValueName + ','
								}
							}
						}
						//规格结束
						const goods_info = {
							goodsid: this.id,
							skuAttrValueIds: this.skuAttrValueIds,
							num: this.lsnum.toString(),
						}
						this.$parent.globalData.goods_info = goods_info
						const goodInfo = {
							title: this.title,
							imgPath: this.imgPath,
							sku: this.sku.substr(0, this.sku.length - 1).split(','),
							point: this.goodsdatilist.point,
							skuPrice: this.goodsdatilist.skuPrice,
							allPoint: this.goodsdatilist.allPoint,
							isPoint: this.goodsdatilist.isPoint,
							payType: '0'
						}
						this.$parent.globalData.goodInfo = goodInfo
						this.show = false
						this.guigeInfo =
							this.goodsMues.goodsTitle + '   ' + this.lsnum + '件'
						wepy.navigateTo({
							url: '../../pages/confirmOrder/confirmorder?state=' + 1,
						})
					}
				} else {
					wx.navigateTo({
						url: '../../pages/Authorization/authorization',
					})
				}
			}
		},
		titleActive(item, attrId) {
			var list = this.goodsdatilist.attr_group_list
			for (var i = 0; i < list.length; i++) {
				if (list[i].attrId == attrId) {
					for (var j = 0; j < list[i].attrValues.length; j++) {
						if (list[i].attrValues[j].attrValueId == item.attrValueId) {
							list[i].attrValues[j].checked = true
						} else {
							list[i].attrValues[j].checked = false
						}
					}
				}
			}
			var idslist = ''
			for (var i = 0; i < list.length; i++) {
				for (var j = 0; j < list[i].attrValues.length; j++) {
					if (list[i].attrValues[j].checked) {
						idslist += list[i].attrValues[j].attrValueId + ','
					}
				}
			}
			this.skuAttrValueIds = idslist.substr(0, idslist.length - 1)
			this.editguige(this.id, this.lsnum, this.skuAttrValueIds)
		},
		// 添加到收藏
		goLike(id) {
			if (wepy.getStorageSync('userId')) {
				if (this.isChecked) {
					//取消收藏
					this.removeGoods(id)
					this.isChecked = !this.isChecked
				} else {
					//收藏
					this.addLike(id)
					this.isChecked = !this.isChecked
				}
			} else {
				wx.navigateTo({
					url: '../../pages/Authorization/authorization',
				})
			}
		},
		// 点击跳转到购物车
		gouCart() {
			wepy.switchTab({
				url: '../../pages/tabs/cart',
			})
		},
		// 点击客服按钮
		onCall() {
			console.log('点击了客服')
			wepy
				.makePhoneCall({
					phoneNumber: '15309272033',
				})
				.catch((err) => console.log('用户点击了取消'))
		},
		showfenxiang() {
			this.fenxiang = true
		},
		canceling() {
			this.fenxiang = false
		},
		// 点击发送给好友
		sharefriend(res) {
			if (res.from == 'button') {
				console.log(res.target, res)
			}
			return {
				title: '快来看看吧，我给你分享了一个商品',
				path: '../../pages/goodsDatils/goodsdatils?id=' + this.id, //这里是被分享的人点击进来之后的页面
				imageUrl: this.shareQrImg, //这里是图片的路径
			}
		},
		//关闭分享海报
		closeShare() {
			this.showSharePic = false
		},
		//保存图片
		async savePic() {
			let that = this
			wx.getSetting({
				success: (res) => {
					if (res.authSetting['scope.writePhotosAlbum'] == false) {
						wx.showModal({
							title: '提示',
							content: '是否授权将相册保存到相册？',
							confirmColor: '#2ca2ed',
							success: (res) => {
								//点击确定打开授权设置
								if (res.confirm) {
									wx.openSetting({
										success: (res) => {
											setTimeout(() => {
												if (res.authSetting['scope.writePhotosAlbum'] == true) {
													wx.saveImageToPhotosAlbum({
														filePath: that.sharePicUrl,
														success: (res) => {
															that.showSharePic = false
															that.fenxiang = false
															that.$apply()
															wx.showToast({
																title: '保存成功！',
																icon: 'success',
																mask: true,
															})
														},
														fail: (err) => {
															wx.showToast({
																title: '保存失败！',
																icon: 'none',
																mask: true,
															})
														},
													})
												} else {
													wx.showToast({
														title: '保存失败！',
														icon: 'none',
														mask: true,
													})
												}
											}, 500)
										},
									})
								}
							},
						})
					} else {
						wx.saveImageToPhotosAlbum({
							filePath: that.sharePicUrl,
							success: (res) => {
								that.showSharePic = false
								that.fenxiang = false
								that.$apply()
								wx.showToast({
									title: '保存成功！',
									icon: 'success',
									mask: true,
								})

							},
						})
					}
				},
			})
		},
	}
	ggvvc() {
		this.show = false;
		//立即购买
		this.goodsMues.goodsTitle = ''
		this.skuAttrValueIds = ''
		//规格开始
		var list = this.goodsdatilist.attr_group_list
		var skuAttrValueIds = ''
		for (var i = 0; i < list.length; i++) {
			for (var j = 0; j < list[i].attrValues.length; j++) {
				if (list[i].attrValues[j].checked == true) {
					this.goodsMues.goodsTitle +=
						list[i].attrValues[j].attrValueName + ''
					skuAttrValueIds += list[i].attrValues[j].attrValueId + ','
				}
			}
		}
		this.skuAttrValueIds = skuAttrValueIds.substr(
			0,
			skuAttrValueIds.length - 1
		)
		this.sku = ''
		for (var i = 0; i < list.length; i++) {
			for (var j = 0; j < list[i].attrValues.length; j++) {
				if (list[i].attrValues[j].checked == true) {
					this.sku += list[i].attrValues[j].attrValueName + ','
				}
			}
		}
		//规格结束
		const goods_info = {
			goodsid: this.id,
			skuAttrValueIds: this.skuAttrValueIds,
			num: this.lsnum.toString(),
		}
		this.$parent.globalData.goods_info = goods_info
		const goodInfo = {
			title: this.title,
			imgPath: this.imgPath,
			sku: this.sku.substr(0, this.sku.length - 1).split(','),
			point: this.goodsdatilist.point,
			skuPrice: this.goodsdatilist.skuPrice,
			allPoint: this.goodsdatilist.allPoint,
			isPoint: this.goodsdatilist.isPoint,
			payType: this.jfdhfs
		}
		this.$parent.globalData.goodInfo = goodInfo
		this.show = false
		this.guigeInfo =
			this.goodsMues.goodsTitle + '   ' + this.lsnum + '件'
		wepy.navigateTo({
			url: '../../pages/confirmOrder/confirmorder?state=' + 1,
		})
	}
	// 获取商品详情数据
	async getGoodsDatil() {
		const res = await wepy.post('baseRest/getGoodsDetail', {
			id: this.id,
			memberId: wepy.getStorageSync('userId'),
			shoppingCartId: this.shoppingCartId
		})
		console.log(res)
		if (res.statusCode != 200) {
			return wepy.noToast('获取商品信息失败')
		}
		var that = this
		let goodsINfo = res.data.data
		that.title = res.data.data.name
		that.shareTitle = res.data.data.name
		that.skuPrice = res.data.data.skuPrice
		that.imgPath = res.data.data.filePath
		that.shareCoverImg = res.data.data.filePath
		if (goodsINfo.isPub == 1) {
			wepy.noToast('此商品已下架')
		} else if (goodsINfo.skuNum == 0) {
			wepy.noToast('此商品库存不足')
		}
		//秒杀
		if (goodsINfo.isSeckill) {
			that.daojishi = true
			that.time = goodsINfo.remainTime
			that.$parent.globalData.seckillGoodId = goodsINfo.secKillGoodsId
		}
		if (goodsINfo.images == '') {
			var ss = {
				imgPath: that.urls + '/' + that.zhanweit,
			}
			goodsINfo.images.push(ss)
		}
		console.log(goodsINfo, 'pppppppp')
		that.goodsdatilist = goodsINfo
		goodsINfo.content = goodsINfo.content.replace(
			/\<table/gi,
			'<table style="width:100%;"'
		)
		goodsINfo.content = goodsINfo.content.replace(
			/\<img/gi,
			'<img style="width:100%;height:auto;display:block"'
		)
		goodsINfo.content = goodsINfo.content.replace(
			/\<p/gi,
			'<p style="width:100%;word-wrap:noraml;"'
		)
		that.goods_info.goods_img = goodsINfo.skuImg;
		that.goodsdatilist.skuYuanPrice = goodsINfo.marketPrice;
		console.log(that.goodsdatilist, '======--------')
		if (goodsINfo.is_favorite == 1) {
			that.isChecked = true
		} else {
			that.isChecked = false
		}
		console.log(that.skuAttrValueIds, '555555555555')
		if (that.skuAttrValueIds != '') {
			//购物车进入
			that.editguige(that.id, that.lsnum, that.skuAttrValueIds)
			var skuAttrValueIds = that.skuAttrValueIds
			skuAttrValueIds = skuAttrValueIds.split(',')
			for (var i = 0; i < goodsINfo.attr_group_list.length; i++) {
				for (
					var j = 0; j < goodsINfo.attr_group_list[i].attrValues.length; j++
				) {
					if (
						goodsINfo.attr_group_list[i].attrValues[j].attrValueId ==
						skuAttrValueIds[i]
					) {
						goodsINfo.attr_group_list[i].attrValues[j].checked = true
					} else {
						goodsINfo.attr_group_list[i].attrValues[j].checked = false
					}
				}
			}
		} else {
			//单商品进入
			var sspp = ''
			var skuAttrValueIds = ''
			for (var i = 0; i < goodsINfo.attr_group_list.length; i++) {
				for (
					var j = 0; j < goodsINfo.attr_group_list[i].attrValues.length; j++
				) {
					if (goodsINfo.attr_group_list[i].attrValues[j].checked == true) {
						that.show = false
						sspp +=
							goodsINfo.attr_group_list[i].attrValues[j].attrValueName + ','
						skuAttrValueIds +=
							goodsINfo.attr_group_list[i].attrValues[j].attrValueId + ','
					}
				}
			}
			that.skuAttrValueIds = skuAttrValueIds.substr(
				0,
				skuAttrValueIds.length - 1
			)
			that.sku = sspp
			sspp = sspp.substr(0, sspp.length - 1).split(',')
			that.guigeInfo = sspp + ' ' + '1件'
			that.$apply()
		}
	}
	// 添加到收藏
	async addLike(id) {
		const res = await wepy.post('baseRest/saveMemberSpuAss', {
			spuId: id,
			memberId: this.userId,
		})
		if (res.statusCode != 200) {
			return wepy.noToast('获取商品信息失败')
		}
		wepy.baseToast('收藏成功')
	}
	// 取消收藏
	async removeGoods(id) {
		const res = await wepy.post('baseRest/saveMemberSpuAss', {
			memberId: wepy.getStorageSync('userId'),
			spuId: id,
		})
		if (res.statusCode != 200) {
			return wepy.noToast('取消失败')
		}
		wepy.baseToast('取消成功')
		console.log(res)
	}
	// 获取默认地址
	async getAddressdefalt() {
		const res = await wepy.post('baseRest/getDefaultAddr', {
			memberId: this.userId,
		})
		console.log('获取默认地址', res)
		if (res.statusCode != 200) {
			wepy.noToast('获取地址失败')
		}
		this.getaddressDeftInfo = res.data.data
		this.$apply()
	}
	// 查询满减
	async getManJian(id) {
		const {
			data: res
		} = await wepy.post('baseRest/queryReductionBySpu', {
			spuId: id,
		})
		console.log('满减', res)
		if (res.state != 1) {
			return wepy.noToast('网络错误请稍后重试')
		}
		if (res.data) {
			this.ManJian = res.data.ruleBeanList
			this.satisfyPrice = res.data.ruleBeanList[0].satisfyPrice
			this.manJianMOney = res.data.ruleBeanList[0].reducePrice
		}
		this.$apply()
	}
	// 选择规格
	async editguige(id, goodsNum, skuAttrValueIds) {
		const res = await wepy.post('baseRest/getChooseGoodsSku', {
			id: id,
			num: JSON.stringify(goodsNum),
			skuAttrValueIds: skuAttrValueIds,
		})
		console.log(res.data)
		if (res.data.state == 1) {
			var data = res.data.data
			if (data.skuNum == 0) {
				wepy.noToast('此规格商品库存不足,请重新选择')
			}
			//秒杀活动id
			if (data.isSeckill) {
				this.daojishi = true
				this.time = data.remainTime
				this.$parent.globalData.seckillGoodId = data.secKillGoodsId
				this.goodsdatilist.marketPrice = data.marketPrice
			}
			this.goodsdatilist.skuNum = data.skuNum
			this.goods_info.goods_img = data.skuImg
			this.goodsdatilist.skuPrice = data.skuPrice
			this.goodsdatilist.point = data.point
			this.goodsdatilist.allPoint = data.allPoint
			this.goodsdatilist.skuYuanPrice = data.skuYuanPrice
			this.skuPrice = data.skuPrice

			console.log(typeof data.num)
			this.lsnum = data.num
			this.goodsMues.goodsTitle = data.skuAttrCodeNames;
			this.guigeInfo = data.skuAttrCodeNames + ' ' + data.num + '件'

			this.$apply()
		} else {
			return wepy.noToast(res.data.message)
		}
	}
	// 获取配送信息
	async getsendInfo() {
		const {
			data: res
		} = await wepy.post('baseRest/getDictionaryList', {
			parentId: '106',
		})
		console.log('配送信息', res)
		if (res.state != 1) {
			return wepy.noToast('网络异常，请稍后重试')
		}
		this.sendLi = res.data[0].name
		this.$apply()
	}
	async gouwuche() {
		const res = await wepy.post('baseRest/saveShoppingCart', {
			memberId: this.userId,
			spuId: this.id,
			skuAttrValueIds: this.skuAttrValueIds,
			buyNum: this.lsnum.toString(),
		})
		console.log(res)
		if (res.statusCode != 200) {
			return wepy.noToast('加入购物车失败')
		} else {
			this.show = false
			this.$apply()
			return wepy.noToast('已加入购物车')
		}
	}
	roundRect(ctx, x, y, w, h, r) {
		if (w < 2 * r) {
			r = w / 2;
		}
		if (h < 2 * r) {
			r = h / 2;
		}

		ctx.beginPath();
		ctx.setStrokeStyle('white')

		ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5);
		ctx.moveTo(x + r, y);
		ctx.lineTo(x + w - r, y);
		ctx.lineTo(x + w, y + r);

		ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2);
		ctx.lineTo(x + w, y + h - r);
		ctx.lineTo(x + w - r, y + h);

		ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5);
		ctx.lineTo(x + r, y + h);
		ctx.lineTo(x, y + h - r);

		ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI);
		ctx.lineTo(x, y + r);
		ctx.lineTo(x + r, y);

		ctx.stroke()
		ctx.closePath();
	}
	// 海报开始
	// 绘图
	drawImg(rjlogo, logo, headIcon, code) {
		console.log(rjlogo, logo, headIcon, code, "------=========")
		let title = this.shareTitle // 标题

		let w = 0
		wx.getSystemInfo({
			success: function(res) {
				w = res.screenWidth
			},
		})

		let ctx = wx.createCanvasContext('shareFrends')

		ctx.fillStyle = '#ffffff'
		ctx.fillRect(0, 0, (w / 750) * 670 * 2, (w / 750) * 744 * 2)
		//绘制logo
		ctx.drawImage(rjlogo, (w / 750) * 670 * 0.06, (w / 750) * 670 * 0.05, (w / 750) * 670 * 0.4, (w / 750) * 670 *
			0.3)
		//绘制文本
		ctx.setFontSize(20)
		ctx.setFillStyle('#212121')
		ctx.fillText('荣家全渠道智慧物业服务平台', (w / 750) * 670 * 1 - 180, (w / 750) * 670 * 0.17)
		ctx.setFontSize(16)
		ctx.setFillStyle('#9f9f9f')
		ctx.fillText('给你推荐一个好东西!', (w / 750) * 670 * 1 - 180, (w / 750) * 670 * 0.26)
		ctx.save()

		//绘制虚线、
		ctx.lineWidth = 1;
		ctx.strokeStyle = '#ccc';
		ctx.beginPath();
		ctx.setLineDash([5]);
		ctx.moveTo(0, 130);
		ctx.lineTo((w / 750) * 670 * 1.8, 130);
		ctx.stroke();
		
		//绘制商品图
		ctx.drawImage(logo, 40, 140, (w / 750) * 670 * 1.5, (w / 750) * 670 * 1)

		// ctx.setFontSize(14)
		// ctx.fillStyle = "#9f9f9f";
		// ctx.fillText('市场价:', 40, (w / 750) * 670 * 1.6)

		// ctx.setFontSize(12)
		// ctx.fillStyle = "#9f9f9f";
		// ctx.fillText('￥', 90, (w / 750) * 670 * 1.6)

		// ctx.setFontSize(20)
		// ctx.fillStyle = "#9f9f9f";
		// ctx.fillText(this.goodsdatilist.marketPrice, 100, (w / 750) * 670 * 1.6)
		
		// ctx.lineWidth = 1;
		// ctx.strokeStyle = '#9f9f9f';
		// ctx.beginPath();
		// // ctx.setLineDash([1]);
		// ctx.moveTo(35, (w / 750) * 670 * 1.58)
		// ctx.lineTo(125, (w / 750) * 670 * 1.58)
		
		ctx.stroke()

		var names = '';
		if (this.goodsdatilist.name.length > 12) {
			names = this.goodsdatilist.name.slice(0, 12) + '...'
		} else {
			names = this.goodsdatilist.name
		}
		ctx.setFontSize(24)
		ctx.fillStyle = "#000";
		ctx.fillText(names, 40, (w / 750) * 670 * 1.53)

		ctx.setFontSize(16)
		ctx.fillStyle = "#212121";
		ctx.fillText(this.guigeInfo, 40, (w / 750) * 670 * 1.62)
		
		ctx.setFontSize(24)
		ctx.fillStyle = "#f34133";
		ctx.fillText('￥', 40, (w / 750) * 670 * 1.78)

		ctx.setFontSize(30)
		ctx.fillStyle = "#f34133";
		ctx.fillText(this.goodsdatilist.skuPrice, 70, (w / 750) * 670 * 1.78)


		/ ctx.setFontSize(14)
		ctx.fillStyle = "#9f9f9f";
		ctx.fillText('市场价:', 135, (w / 750) * 670 * 1.78)
		ctx.setStrokeStyle('#999999')
        ctx.strokeRect(135, (w / 750) * 670 * 1.76, 100, 1)

		ctx.setFontSize(12)
		ctx.fillStyle = "#9f9f9f";
		ctx.fillText('￥', 190, (w / 750) * 670 * 1.78)

		ctx.setFontSize(20)
		ctx.fillStyle = "#9f9f9f";
		ctx.fillText(this.goodsdatilist.marketPrice, 205, (w / 750) * 670 * 1.78)

		ctx.setFontSize(16)
		ctx.fillStyle = "#9f9f9f";
		ctx.fillText('荣家为西安荣鑫物业管理有限公司打造的', (w / 750) * 670 * 0.4, (w / 750) * 670 * 2)

		ctx.setFontSize(16)
		ctx.fillStyle = "#9f9f9f";
		ctx.fillText('全渠道物业智慧服务平台', (w / 750) * 670 * 0.6, (w / 750) * 670 * 2.1)
		ctx.stroke()

		ctx.save()
		//绘制小程序二维码
		ctx.drawImage(code, (w / 750) * 670 * 1.15, (w / 750) * 670 * 1.4, (w / 750) * 670 * 0.5, (w / 750) * 670 * 0.4)
		ctx.setFontSize(14)
		ctx.fillStyle = "#212121";
		ctx.fillText('长按查看该商品', (w / 750) * 670 * 1.25, (w / 750) * 670 * 1.85)
		ctx.stroke()
		ctx.draw(false, () => {
			//调用接口将画布转换为图片
			wx.canvasToTempFilePath({
				x: 0,
				y: 0,
				fileType: 'jpg',
				quality: 1,
				width: (w / 750) * 660 * 2,
				height: (w / 750) * 744 * 2,
				destWidth: (w / 750) * 670 * 3,
				destHeight: (w / 750) * 744 * 4,
				canvasId: 'shareFrends',
				success: (res) => {
					wx.hideToast()
					console.log(res, '00000000')
					if (res.tempFilePath) {
						this.sharePicUrl = res.tempFilePath //生成的图片路径
						this.share = false
						this.showSharePic = true
						this.$apply()
					}
				},
				fail(err) {
					wx.showToast({
						title: '图片生成失败，请稍候再试！',
						icon: 'none',
						mask: true,
					})
				},
			})
		})
	}


	//获取logo
	getLogo() {
		console.log(this.shareCoverImg, "333333333")
		return new Promise((resolve, reject) => {
			wx.downloadFile({
				url: this.shareCoverImg,
				success: (res) => {
					resolve(res.tempFilePath)
				},
				fail: (err) => {
					console.log(er)
				},
			})
		})
	}
	
	//获取二维码
	getCode() {
		console.log(this.shareQrImg, "222222222")
		return new Promise((resolve, reject) => {
			wx.downloadFile({
				url: this.shareQrImg,
				success: (res) => {
					resolve(res.tempFilePath)
				},
				fail: (err) => {
					console.log(er)
				},
			})
		})
	}
	
	getrjlogo() {
		console.log(this.rjlogo, "111111")
		return new Promise((resolve, reject) => {
			wx.downloadFile({
				url: this.rjlogo,
				success: (res) => {
					resolve(res.tempFilePath)
				},
				fail: (err) => {
					console.log(er)
				},
			})
		})
	}
	
	// 获取海报二维码
	async geterweiMa() {
		const {
			data: res
		} = await wepy.post('baseRest/getShareErcode', {
			spuId: this.id,
		})
		console.log('二维码', res)
		if (res.state != 1) {
			return wepy.noToast('网络异常')
		}
		this.shareQrImg = res.data
		this.$apply()
	}
}
